<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CollOption extends Model
{
    //设置表的类型和表名
    protected $table = 'coll_options';
    protected $primaryKey = 'id';
    public $timestamps = false;
    protected $fillable = [
        'opt_name', 'opt_id', 'sign', 'opt_sort'
    ];

    /**
     * 说明:获取指定菜单例数据
     * $sign:指定菜单的标示
     * @return array
     */
    public static function getOption($sign)
    {
        $option = self::where('sign', $sign)->orderBy('opt_id', 'asc')->get();
        $option = setSort($option, 'opt_sort');
        $optionArray = array();
        foreach ($option as $key => $value) {
            $optionArray[] = array('text' => $value['opt_name'], 'value' => $value['opt_id']);
        }
        return $optionArray;
    }


    /**
     * 说明：获取指定的选项id的中文值
     * $opt_id:选项编号
     * $sign:选项标识
     * @return： 选项名称
     */
    public static function getOptionName($opt_id, $sign)
    {
//        var_dump($sign);
//        $options=array();
//        if (Cache::has('options')) {
//            $options= Cache::get('options');
//        }else {
        $options = self::get()->toArray();
//        }
//        var_dump($options);
        foreach ($options as $v) {
            if ($v['sign'] == $sign && $v['opt_id'] == $opt_id) {
                return $v['opt_name'];
            }
        }
        return '';
    }
}
